package com.corner.model.cornerservice.service.exception;

import com.corner.app.App;
import com.corner.app.ConsTants;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

public class BaseException extends Exception {

    public static final String ObjectNotFound = "407";

    public static final String CODE = "code";

    public static final String QueryNoResult = "408";

    public static final String PhoneNumHasUsed = "409";

    public static final String PasswordNotMatch = "410";

    public static final String PhoneNumNotFound = "411";

    public static final String UnKnownError = "499";


    private static Properties properties;

    static {
        try {
            properties = new Properties();
            properties.load(new InputStreamReader(App.application.getAssets().open("exceptions.properties"), ConsTants.ENCODING));
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("BaseExceptions init error");
        }
    }

    private String code;
    private String message;

    @Override
    public String getMessage() {
        return message;
    }

    public BaseException(String code) {
        this.code = code;
        message = properties.getProperty(code);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    @Override
    public void printStackTrace() {
        super.printStackTrace();
        StringBuilder sb = new StringBuilder();
        sb.append("exceptionCode:").append(code).append(",").append("message:").append(message);
        System.out.println(sb.toString());
    }
}
